package com.example.chatroom.controller;

import com.example.chatroom.common.AjaxResult;
import com.example.chatroom.common.UserSessionTools;
import com.example.chatroom.entity.FriendEntity;
import com.example.chatroom.entity.UserEntity;
import com.example.chatroom.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class FriendController {
    @Autowired
    private FriendService friendService;

    // todo: 获取当前用户的好友列表
    @RequestMapping("/friendList")
    public AjaxResult selectFriendList(HttpServletRequest request){
        List<FriendEntity> friendList = null;
        // 从会话中，获取userId
        UserEntity user = UserSessionTools.getLoginUser(request);
        if(user == null || user.getUser_id() <= 0)
            return AjaxResult.fail(-1,"当前用户未登录",friendList);
        friendList = friendService.selectFriendList(user.getUser_id());
        return AjaxResult.success("获取好友列表成功！",friendList);
    }
}
